home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / PInterfaces / fenv.p < prev    next >
Encoding:
Text File  |  1998-08-17  |  11.1 KB  |  275 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        fenv.p
  3.  
  4.      Contains:    Floating-Point environment for PowerPC and 68K
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1987-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. }
  17. {$IFC UNDEFINED UsingIncludes}
  18. {$SETC UsingIncludes := 0}
  19. {$ENDC}
  20.  
  21. {$IFC NOT UsingIncludes}
  22.  UNIT fenv;
  23.  INTERFACE
  24. {$ENDC}
  25.  
  26. {$IFC UNDEFINED __FENV__}
  27. {$SETC __FENV__ := 1}
  28.  
  29. {$I+}
  30. {$SETC fenvIncludes := UsingIncludes}
  31. {$SETC UsingIncludes := 1}
  32.  
  33. {$IFC UNDEFINED __CONDITIONALMACROS__}
  34. {$I ConditionalMacros.p}
  35. {$ENDC}
  36.  
  37.  
  38. {$PUSH}
  39. {$ALIGN MAC68K}
  40. {$LibExport+}
  41.  
  42. {$IFC TARGET_OS_MAC }
  43. {
  44.     A collection of functions designed to provide access to the floating
  45.     point environment for numerical programming. It is modeled after
  46.     the floating-point requirements in C9X.
  47.     
  48.     The file <fenv.h> declares many functions in support of numerical
  49.     programming.  It provides a set of environmental controls similar to
  50.     the ones found in <SANE.h>.  Programs that test flags or run under
  51.     non-default modes must do so under the effect of an enabling
  52.     "fenv_access" pragma.
  53. }
  54.  
  55. {*******************************************************************************
  56. *                                                                                *
  57. *    fenv_t         is a type for representing the entire floating-point        *
  58. *                     environment in a single object.                              *
  59. *                                                                                *
  60. *     fexcept_t        is a type for representing the floating-point                *
  61. *                     exception flag state collectively.                           *
  62. *                                                                                *
  63. *******************************************************************************}
  64. {$IFC TARGET_CPU_PPC }
  65.  
  66. TYPE
  67.     fenv_t                                = LONGINT;
  68.     fexcept_t                            = LONGINT;
  69. {    Definitions of floating-point exception macros                          }
  70.  
  71. CONST
  72.     FE_INEXACT                    = $02000000;
  73.     FE_DIVBYZERO                = $04000000;
  74.     FE_UNDERFLOW                = $08000000;
  75.     FE_OVERFLOW                    = $10000000;
  76.     FE_INVALID                    = $20000000;
  77.  
  78.  
  79. {    Definitions of rounding direction macros                                }
  80.     FE_TONEAREST                = $00000000;
  81.     FE_TOWARDZERO                = $00000001;
  82.     FE_UPWARD                    = $00000002;
  83.     FE_DOWNWARD                    = $00000003;
  84.  
  85. {$ENDC}
  86. {$IFC TARGET_CPU_68K }
  87. {$IFC TARGET_RT_MAC_68881 }
  88.  
  89. TYPE
  90.     fexcept_t                            = LONGINT;
  91.     fenv_tPtr = ^fenv_t;
  92.     fenv_t = RECORD
  93.         FPCR:                    LONGINT;
  94.         FPSR:                    LONGINT;
  95.     END;
  96.  
  97.  
  98. CONST
  99.     FE_INEXACT                    = $00000008;                    {  ((long)(8))    }
  100.     FE_DIVBYZERO                = $00000010;                    {  ((long)(16))   }
  101.     FE_UNDERFLOW                = $00000020;                    {  ((long)(32))   }
  102.     FE_OVERFLOW                    = $00000040;                    {  ((long)(64))   }
  103.     FE_INVALID                    = $00000080;                    {  ((long)(128))  }
  104.  
  105. {$ELSEC}
  106.  
  107. TYPE
  108.     fexcept_t                            = INTEGER;
  109.     fenv_t                                = INTEGER;
  110.  
  111. CONST
  112.     FE_INVALID                    = $0001;                        {  ((short)(1))   }
  113.     FE_UNDERFLOW                = $0002;                        {  ((short)(2))   }
  114.     FE_OVERFLOW                    = $0004;                        {  ((short)(4))   }
  115.     FE_DIVBYZERO                = $0008;                        {  ((short)(8))   }
  116.     FE_INEXACT                    = $0010;                        {  ((short)(16))  }
  117.  
  118. {$ENDC}
  119.     FE_TONEAREST                = $0000;                        {  ((short)(0))   }
  120.     FE_UPWARD                    = $0001;                        {  ((short)(1))   }
  121.     FE_DOWNWARD                    = $0002;                        {  ((short)(2))   }
  122.     FE_TOWARDZERO                = $0003;                        {  ((short)(3))   }
  123.  
  124. {    Definitions of rounding precision macros  (68K only)                    }
  125.     FE_LDBLPREC                    = $0000;                        {  ((short)(0))   }
  126.     FE_DBLPREC                    = $0001;                        {  ((short)(1))   }
  127.     FE_FLTPREC                    = $0002;                        {  ((short)(2))   }
  128.  
  129. {$ENDC}
  130. {    The bitwise OR of all exception macros                                  }
  131.  
  132. CONST
  133.     FE_ALL_EXCEPT = ( FE_INEXACT + FE_DIVBYZERO + FE_UNDERFLOW + FE_OVERFLOW + FE_INVALID );
  134.  
  135. {    Definition of pointer to IEEE default environment object               }
  136. VAR
  137.  {$PUSH}
  138.  {$J+}
  139.  _FE_DFL_ENV: fenv_t;               { default environment object        }
  140.  {$POP}
  141.  
  142. {******************************************************************************
  143. *     The following functions provide access to the exception flags.  The      *
  144. *     "int" input argument can be constructed by bitwise ORs of the exception  *
  145. *     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  146. ******************************************************************************}
  147. {******************************************************************************
  148. *     The function "feclearexcept" clears the supported exceptions represented *
  149. *     by its argument.                                                         *
  150. ******************************************************************************}
  151. PROCEDURE feclearexcept(excepts: LONGINT); C;
  152.  
  153.  
  154. {******************************************************************************
  155. *    The function "fegetexcept" stores a representation of the exception       *
  156. *     flags indicated by the argument "excepts" through the pointer argument   *
  157. *     "flagp".                                                                 *
  158. ******************************************************************************}
  159. PROCEDURE fegetexcept(VAR flagp: fexcept_t; excepts: LONGINT); C;
  160.  
  161.  
  162. {******************************************************************************
  163. *     The function "feraiseexcept" raises the supported exceptions             *
  164. *     represented by its argument.                                             *
  165. ******************************************************************************}
  166. PROCEDURE feraiseexcept(excepts: LONGINT); C;
  167.  
  168.  
  169. {******************************************************************************
  170. *     The function "fesetexcept" sets or clears the exception flags indicated  *
  171. *     by the int argument "excepts" according to the representation in the     *
  172. *     object pointed to by the pointer argument "flagp".  The value of         *
  173. *     "*flagp" must have been set by a previous call to "fegetexcept".         *
  174. *     This function does not raise exceptions; it just sets the state of       *
  175. *     the flags.                                                               *
  176. ******************************************************************************}
  177. PROCEDURE fesetexcept({CONST}VAR flagp: fexcept_t; excepts: LONGINT); C;
  178.  
  179.  
  180. {******************************************************************************
  181. *     The function "fetestexcept" determines which of the specified subset of  *
  182. *     the exception flags are currently set.  The argument "excepts" specifies *
  183. *     the exception flags to be queried as a bitwise OR of the exception       *
  184. *     macros.  This function returns the bitwise OR of the exception macros    *
  185. *     corresponding to the currently set exceptions included in "excepts".     *
  186. ******************************************************************************}
  187. FUNCTION fetestexcept(excepts: LONGINT): LONGINT; C;
  188.  
  189.  
  190. {******************************************************************************
  191. *     The following functions provide control of rounding direction modes.     *
  192. ******************************************************************************}
  193. {******************************************************************************
  194. *     The function "fegetround" returns the value of the rounding direction    *
  195. *     macro which represents the current rounding direction.                   *
  196. ******************************************************************************}
  197. FUNCTION fegetround: LONGINT; C;
  198.  
  199.  
  200. {******************************************************************************
  201. *     The function "fesetround" establishes the rounding direction represented *
  202. *     by its argument.  It returns nonzero if and only if the argument matches *
  203. *     a rounding direction macro.  If not, the rounding direction is not       *
  204. *     changed.                                                                 *
  205. ******************************************************************************}
  206. FUNCTION fesetround(round: LONGINT): LONGINT; C;
  207.  
  208.  
  209. {******************************************************************************
  210. *    The following functions manage the floating-point environment, exception  *
  211. *    flags and dynamic modes, as one entity.                                   *
  212. ******************************************************************************}
  213. {******************************************************************************
  214. *     The function "fegetenv" stores the current floating-point environment    *
  215. *     in the object pointed to by its pointer argument "envp".                 *
  216. ******************************************************************************}
  217. PROCEDURE fegetenv(VAR envp: fenv_t); C;
  218.  
  219.  
  220. {******************************************************************************
  221. *     The function "feholdexcept" saves the current environment in the object  *
  222. *     pointed to by its pointer argument "envp", clears the exception flags,   *
  223. *     and clears floating-point exception enables.  This function supersedes   *
  224. *     the SANE function "procentry", but it does not change the current        *
  225. *     rounding direction mode.                                                 *
  226. ******************************************************************************}
  227. FUNCTION feholdexcept(VAR envp: fenv_t): LONGINT; C;
  228.  
  229.  
  230. {******************************************************************************
  231. *     The function "fesetenv" installs the floating-point environment          *
  232. *     environment represented by the object pointed to by its argument         *
  233. *     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  234. *     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  235. *     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  236. ******************************************************************************}
  237. PROCEDURE fesetenv({CONST}VAR envp: fenv_t); C;
  238.  
  239.  
  240. {******************************************************************************
  241. *     The function "feupdateenv" saves the current exceptions into its         *
  242. *     automatic storage, installs the environment represented through its      *
  243. *     pointer argument "envp", and then re-raises the saved exceptions.        *
  244. *     This function, which supersedes the SANE function "procexit", can be     *
  245. *     used in conjunction with "feholdexcept" to write routines which hide     *
  246. *     spurious exceptions from their callers.                                  *
  247. ******************************************************************************}
  248. PROCEDURE feupdateenv({CONST}VAR envp: fenv_t); C;
  249.  
  250.  
  251. {$IFC TARGET_CPU_68K }
  252. {******************************************************************************
  253. *     The following functions provide control of rounding precision.           *
  254. *     Because the PowerPC does not provide this capability, these functions    *  
  255. *     are available only for the 68K Macintosh.  Rounding precision values     *
  256. *     are defined by the rounding precision macros.  These functions are       *
  257. *     equivalent to the SANE functions getprecision and setprecision.          *
  258. ******************************************************************************}
  259. FUNCTION fegetprec: LONGINT; C;
  260. FUNCTION fesetprec(precision: LONGINT): LONGINT; C;
  261. {$ENDC}
  262. {$ENDC}  {TARGET_OS_MAC}
  263.  
  264.  
  265. {$ALIGN RESET}
  266. {$POP}
  267.  
  268. {$SETC UsingIncludes := fenvIncludes}
  269.  
  270. {$ENDC} {__FENV__}
  271.  
  272. {$IFC NOT UsingIncludes}
  273.  END.
  274. {$ENDC}
  275.